# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: Simone Sclavi 'Ito' <darkhado@gmail.com>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - removed makedepends on nasm and java, -DWITH_JAVA=OFF
#  - added -DWITH_SIMD=FALSE to configure for !AArch64

pkgname=libjpeg-turbo
pkgver=2.1.0
pkgrel=1
pkgdesc='JPEG image codec with accelerated baseline compression and decompression'
url='https://libjpeg-turbo.org/'
arch=('x86_64')
license=('BSD')
depends=('glibc')
makedepends=('cmake')
provides=('libjpeg' 'libjpeg.so' 'libturbojpeg.so')
source=("https://sourceforge.net/projects/${pkgname}/files/${pkgver}/${pkgname}-${pkgver}.tar.gz"{,.sig})
sha512sums=('6632a2a71cb3a350fe4f850fe84e51e361755c373babf2b47fb164c3a9fc3fd66705639bebedd8c1b40cf6c15fd702e814425b0be5919048987bbec357828605'
            'SKIP')
b2sums=('693eccd00e8e1574e60ceb7464552ce9c4fd370c5ec4fc0dc3696ead7b4cd031228aaaf0eef3ceba194bb96bac6134b9c951162c0b81e88637edd6e71f4577f7'
        'SKIP')
validpgpkeys=('0338C8D8D9FDA62CF9C421BD7EC2DBB6F4DBF434') # The libjpeg-turbo Project (Signing key for official binaries) <information@libjpeg-turbo.org>

build() {
  cd "${pkgname}-${pkgver}"
  [[ $CARCH != "aarch64" ]] && CONFIG="-DWITH_SIMD=FALSE"
  cmake -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_INSTALL_LIBDIR=/usr/lib \
        -DCMAKE_BUILD_TYPE='None' \
        -DWITH_JAVA=OFF \
        -DWITH_JPEG8=ON \
        -W no-dev \
        -B build $CONFIG \
        -S .
  make VERBOSE=1 -C build
}

check() {
  cd "${pkgname}-${pkgver}"
  make test -C build
}

package() {
  cd "${pkgname}-${pkgver}"
  make VERBOSE=1 DESTDIR="${pkgdir}" \
       docdir="/usr/share/doc/${pkgname}" \
       exampledir="/usr/share/doc/${pkgname}" \
       install -C build

  install -d "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -s ../../doc/${pkgname}/LICENSE.md "${pkgdir}/usr/share/licenses/${pkgname}"
  # header required by some dependants
  # https://bugs.archlinux.org/task/24787
  install -m 644 jpegint.h "${pkgdir}/usr/include"
}
